import { ADD_TODO, DELETE_TODO, } from "../actions/actionTypes";

const initialState = {
    todoList: [],
};

const todoReducer = (state = initialState, action) => {
    switch(action.type) {
        case ADD_TODO: {
            const { item } = action.payload;
            state.todoList.push(item);
            return { todoList: [...state.todoList], };
        }
        case DELETE_TODO: {
            const { index } = action.payload;
            state.todoList.splice(index, 1);
            return { todoList: [...state.todoList], };
        }
        default:
        return { ...state, };
    }
};

export default todoReducer;